package org.example.edusmart.filter;

import lombok.extern.slf4j.Slf4j;
import org.example.edusmart.utils.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionInterceptor {
    /**
     * 运行时异常
     *
     * @param e 异常信息
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public static Result handleRuntimeException(RuntimeException e) {
        log.error("运行时异常：", e);
        return new Result(404,e.getMessage());
    }

    /**
     * 全局异常捕获
     *
     * @param e 异常信息
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result doException(Exception e) {
        log.error("异常：", e);
        return new Result(404,"系统异常");
    }

}
